package org.example.testdemo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.example.testdemo.mapper.AuthorizeMapper;
import org.example.testdemo.pojo.Authorize;
import org.example.testdemo.pojo.PageReq;
import org.example.testdemo.pojo.combination.AuthorizeInformation;
import org.example.testdemo.service.AuthorizeService;
import org.springframework.stereotype.Service;

@Service
public class AuthorizeServiceImpl implements AuthorizeService {

    @Resource
    private AuthorizeMapper authorizeMapper;


    /**
     * 通过用户名称或项目id查询授权人员
     * @param name 用户名称
     * @param projectId 项目id
     * @return 返回一个授权人员的集合
     */
    @Override
    public IPage<AuthorizeInformation> findByProjectId(String name, String projectId, PageReq req) {
        Page<AuthorizeInformation> page = new Page<>(req.getCurrent(),req.getSize());
        return authorizeMapper.findByProjectId(name,projectId,page);
    }

    /**
     * 新增授权信息
     * @param authorize 授权信息
     * @return 返回0-1的整数
     */
    @Override
    public Integer addAuthorize(Authorize authorize) {
        return authorizeMapper.insert(authorize);
    }

    /**
     * 根据授权id查询授权信息
     * @param id 授权id
     * @return 返回授权信息
     */
    @Override
    public Authorize getAuthorize(String id) {
        QueryWrapper<Authorize> wrapper = new QueryWrapper<>();
        wrapper.eq("authorizeId",id);
        return authorizeMapper.selectOne(wrapper);
    }

    /**
     * 删除授权信息
     * @param id 授权id
     * @return 返回0-1的整数
     */
    @Override
    public Integer deleteAuthorize(String id) {
        return authorizeMapper.deleteById(id);
    }
}
